/*
 * @Author: huangxuzhong
 * @Date: 2022-02-21 13:55:07
 * @LastEditTime: 2022-02-21 14:16:06
 * @LastEditors: Please set LastEditors
 * @Description: 射频配置
 * @FilePath: \macc.admin.vue\src\projectCommon\store\modules\radio\index.js
 */
import { maccApi, requestHttp } from '@utils/index';
const state = {
  channel: {},
};
const mutations = {
  UPDATA_CHANNEL(state, payload) {
    state.channel[payload.cuntry] = payload.channel;
  },
};
const actions = {
  updataRadioChannel({ commit, state }, cuntry) {
    return new Promise((resolve, reject) => {
      let data = {
        api: `${maccApi.RADIO_GETCANNELBYCOUNTRY_GET_API.replace(
          '{country}',
          cuntry
        )}`,
        method: 'GET',
      };
      requestHttp(data)
        .then((res) => {
          if (res && res.code == 0) {
            const channel = {
              cuntry: cuntry,
              channel: Object.assign({}, res.data),
            };
            commit('UPDATA_CHANNEL', channel);
            resolve();
          } else {
            reject(res);
          }
        })
        .catch((error) => {
          reject(error);
        });
    });
  },
};
const getters = {};

export default {
  namespaced: true, //开启命名空间，更好的区分使用stage,防止不同stage模块中的方法重名
  state,
  getters,
  mutations,
  actions,
};
